//
//  LSMsgCell.m
//  LiveStar
//
//  Created by 漪珊 on 2017/4/21.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "LSPrivetaMsgCell.h"
#import "LSMessage.h"
#import "LSPraviteMsgModel.h"

@implementation LSPrivetaMsgCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setSelectionStyle:UITableViewCellSelectionStyleNone];
        [self addSubview:self.avatarImgView];
        [self addSubview:self.msgBackImgView];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    if (_message.msgOwnerType == LSMsgOwnerTypeSelf) {//自己发的
        [self.avatarImgView setOrigin:CGPointMake(self.width - 10 - self.avatarImgView.width, 10)];
    } else {//别人发的
        [self.avatarImgView setOrigin:CGPointMake(10, 10)];
    }
}

- (void)setMessage:(LSMessage *)message {
    _message = message;
    switch (message.msgOwnerType) {
        case LSMsgOwnerTypeSelf:
            [self.avatarImgView setHidden:NO];
            [self.avatarImgView sd_setImageWithURL:[NSURL URLWithString:message.praviteModel.cavatar] placeholderImage:kPlACE_ICON];
            [self.msgBackImgView setHidden:NO];
            self.msgBackImgView.image = [[UIImage imageNamed:@"SenderTextNodeBkg"] resizableImageWithCapInsets:UIEdgeInsetsMake(28, 20, 15, 20) resizingMode:UIImageResizingModeStretch];
            break;
        case LSMsgOwnerTypeOther:
            [self.avatarImgView setHidden:NO];
            [self.avatarImgView sd_setImageWithURL:[NSURL URLWithString:message.praviteModel.cavatar] placeholderImage:kPlACE_ICON];
            [self.msgBackImgView setHidden:NO];
            self.msgBackImgView.image = [[UIImage imageNamed:@"ReceiverTextNodeBkg"] resizableImageWithCapInsets:UIEdgeInsetsMake(28, 20, 15, 20) resizingMode:UIImageResizingModeStretch];
            break;
            
        default:
            break;
    }
}

- (UIImageView *)avatarImgView {
    if (!_avatarImgView) {
        float imageWidth = 40;
        _avatarImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, imageWidth, imageWidth)];
        [_avatarImgView setHidden:YES];
    }
    return _avatarImgView;
}

- (UIImageView *)msgBackImgView {
    if (!_msgBackImgView) {
        _msgBackImgView = [[UIImageView alloc] init];
        [_msgBackImgView setHidden:NO];
    }
    return _msgBackImgView;
}
@end
